/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xuidemo.slice.dropdown;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.DirectionalLayout;
import ohos.app.Context;

import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.view.TitleBarComponent;

/**
 * 下拉框的导航
 *
 * @since 2021-03-30
 */
public class Dropdownboxslice extends AbilitySlice implements Component.ClickedListener {
    private Context context;
    private TitleBarComponent titlect;
    private DependentLayout depenLayout;
    private DirectionalLayout direLayout;

    /**
     * 页面加载
     *
     * @param intent
     */
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_dropdownbox_slicelayout);
        context = this;
        initview();
    }

    private void initview() {
        depenLayout = (DependentLayout) findComponentById(ResourceTable.Id_DepenLayout);
        depenLayout.setClickedListener(this::onClick);
        direLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_DireLayout);
        direLayout.setClickedListener(this::onClick);
        titlect = (TitleBarComponent) findComponentById(ResourceTable.Id_Titlect);
        titlect.setTitile("下拉框");
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_DepenLayout:
                present(new DropdownOneSlice(), new Intent());
                break;
            case ResourceTable.Id_DireLayout:
                present(new DropdownTwoSlice(), new Intent());
                break;
            default:
                break;
        }
    }
}
